<template>
  <scroll-view class="container border-box" scroll-y @scroll="onScroll"
    :style="{ backgroundImage: `url(${VUE_APP_STATIC_URL}ui-static/zwx-static/shop/fenxiaoyuan_bg.png)` }">
    <uni-nav-bar :backgroundColor="scrollPosition > 80 ? '#ff8d09' : 'transparent'" color="#fff" left-icon="back"
      :border="false" :statusBar="true" fixed title="分销员招募令" @clickLeft="$goBack"></uni-nav-bar>
    <!-- 申请分销员 -->
    <view class="topBackImg flex-items flex-column" :style="{
      backgroundImage: `url(${VUE_APP_STATIC_URL}ui-static/zwx-static/shop/fenxiao_content_bg.png)`,
      marginTop: `calc(671rpx - ${navBarHeight}px)`,
    }">
      <view class="dalaba"
        :style="{ backgroundImage: `url(${VUE_APP_STATIC_URL}ui-static/zwx-static/shop/dalaba.png)` }"></view>
      <view class="content border-box">
        <view class="text-box">
          <label class="title">分销员是什么？</label>
          <view class="desc">分销员是我们为拥有推广能力的用户推出的运营计划。你只需将高品质商品分享推荐给他人，收获他人的感谢的同时，挣得属于自己的利润。</view>
        </view>
        <view class="text-box" style="margin-top: 49rpx">
          <label class="title">我该怎么成为分销员？</label>
          <view class="desc">
            <view class="p"><uni-icons type="circle-filled" color="#F8B429" size="15"></uni-icons>
              点击本页面的【我要成为分销员】，即可完成申请。</view>
            <view class="p"><uni-icons type="circle-filled" color="#F8B429" size="15"></uni-icons>
              点击拥有分销员活动标识的分享按钮，将商品分享给好友或朋友圈。</view>
            <view class="p"><uni-icons type="circle-filled" color="#F8B429" size="15"></uni-icons>
              朋友通过您的链接进入并购买一件商品。</view>
            <view class="p"><uni-icons type="circle-filled" color="#F8B429" size="15"></uni-icons>
              我们收到已完成的订单时，会将本订单的佣金结算给您。</view>
            <view class="p"><uni-icons type="circle-filled" color="#F8B429" size="15"></uni-icons>
              返回个人中心-分销中心，查看您的。</view>
          </view>
        </view>
        <view class="text-box" style="margin-top: 49rpx">
          <label class="title">其他说明</label>
          <view class="desc">
            <view class="p"><uni-icons type="circle-filled" color="#F8B429" size="15"></uni-icons>
              客户只有通过您的链接成交，才能返佣给您。</view>
            <view class="p"><uni-icons type="circle-filled" color="#F8B429" size="15"></uni-icons>
              若订单发生退款，我们将去除本订单的佣金。</view>
            <view class="p"><uni-icons type="circle-filled" color="#F8B429" size="15"></uni-icons>
              商品的售后问题，由本商店处理。</view>
            <view class="p"><uni-icons type="circle-filled" color="#F8B429" size="15"></uni-icons>
              不传播任何违法违规信息，一经发现，即被清退，本商城不负任何责任。</view>
            <view class="p"><uni-icons type="circle-filled" color="#F8B429" size="15"></uni-icons>
              以上内容解释权归本商城所有。</view>
          </view>
        </view>
      </view>
    </view>
    <view class="butBox flex-items-plus" @click="informationShowClick">
      <view class="submitbut">我要成为分销员</view>
    </view>
    <!-- 填写信息弹窗 -->
    <u-popup v-model="informationShowFalg" mode="center" border-radius="14">
      <view class="informationShow-box">
        <view class="flex-items flex-column informationShow-centent">
          <view class="mar-top-60">
            <label class="fs-bold fs36">请填写相关信息</label>
          </view>
          <view class="flex-items flex-row mar-top-60">
            <view class="fs26 font-color-656">真实姓名<label class="font-color-red">*</label></view>
            <input class="recruitName mar-left-20 fs26" v-model="userName" />
          </view>
          <view class="flex-items flex-row mar-top-30 phoneStyle">
            <label class="fs26 font-color-656">联系电话<label class="font-color-red">*</label></label>
            <input class="recruitIphone mar-left-20 fs26" disabled="disabled" type="number" v-model="mobile" />
          </view>
          <view class="flex-items flex-row mar-top-30 mar-left-40">
            <label class="fs26 font-color-656">邀请码</label>
            <input class="recruitIphone mar-left-20 fs26" v-model="inviteId" />
          </view>
          <view class="flex-row-plus massageDes-but fs28">
            <view class="exitBut" @click="exitButClick">取消</view>
            <view class="submitbut" @click="applyForRecruit">提交</view>
          </view>
        </view>
      </view>
    </u-popup>
  </scroll-view>
</template>

<script setup>
import { ref, inject, computed, onMounted } from "vue";
import { useStore } from "vuex";
import { request } from "@/utils/request";
import API from "@/config/api";
import { VUE_APP_STATIC_URL } from "@/config/api";
import { onLoad } from "@dcloudio/uni-app";

const $goBack = inject("$goBack");

const store = useStore();
const navBarHeight = computed(
  () => store.state.globalSetting.appSetting.navBarHeight
);

const informationShowFalg = ref(false);
const item = ref("");
const userName = ref("");
const mobile = ref("");
const inviteId = ref("");
const shopId = ref(0);
const isIphone = ref(false);

onLoad((options) => {
  isIphone.value = getApp().globalData.isIphone;
  if (getApp().globalData.distributeRecruitItem) {
    const item = getApp().globalData.distributeRecruitItem;
    shopId.value = parseInt(item.shopId);
    inviteId.value = parseInt(item.invitationCode);
    getApp().globalData.distributeRecruitItem = undefined;
  } else {
    shopId.value = parseInt(options.shopId);
    inviteId.value = parseInt(options.invitationCode);
  }
  isIphone.value = getApp().globalData.isIphone;
});
/**
 * 显示分销员申请弹窗
 */
const informationShowClick = () => {
  const res = uni.getStorageSync("storage_key");
  console.log(res,'res')
  mobile.value = res.phone;
  if (!mobile.value) {
    uni.showToast({
      title: "请先登录!",
      icon: "none",
    });
    uni.navigateTo({
      url: "/zwx_category_page2/userModule/login",
    });
  } else {
    informationShowFalg.value = true;
  }
};
const exitButClick = () => {
  informationShowFalg.value = false;
};

/**
 * 申请为分销员
 */
const applyForRecruit = async () => {
  var regphone = /^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/;
  if (userName.value == "") {
    uni.showToast({
      title: "真实姓名不能为空",
      icon: "none",
    });
  } else if (mobile.value == "") {
    uni.showToast({
      title: "手机号不能为空",
      icon: "none",
    });
  } else if (!regphone.test(mobile.value)) {
    uni.showToast({
      title: "手机格式不正确",
      icon: "none",
    });
  } else {
    try {
      const res = await request(
        API.Apply,
        {
          shopId: shopId.value,
          distributorPhone: mobile.value,
          distributorName: userName.value,
          invitationCode: inviteId.value,
        },
        "POST"
      );
      informationShowFalg.value = false;
      uni.showToast({
        title: "请等候审核...",
      });
      setTimeout(() => {
        uni.navigateBack({
          delta: 1,
        });
      }, 1500);
    } catch (err) {
      uni.showToast({
        title: "申请失败",
        icon: "none",
      });
    }
  }
};

const scrollPosition = ref(0);

// 滚动事件
const onScroll = (event) => {
  scrollPosition.value = event.detail.scrollTop; // 获取滚动位置
};
</script>

<style lang="scss" scoped>
.container {
  background-color: #ff8d09;
  background-size: 100% auto;
  background-repeat: no-repeat;
  height: 100vh;
  overflow: hidden;

  .topBackImg {
    width: 717rpx;
    margin: 0 auto;
    background: #ffb842;
    background-size: 100% auto;
    background-repeat: no-repeat;
    padding-top: 99rpx;
    padding-bottom: 34rpx;
    border-radius: 10rpx;
    position: relative;

    .dalaba {
      width: 144rpx;
      height: 156rpx;
      background-repeat: no-repeat;
      background-size: 100% 100%;
      position: absolute;
      right: 0;
      top: -100rpx;
    }

    .content {
      width: 640rpx;
      background-color: #fff9ee;
      padding: 0 40rpx 84rpx 37rpx;
      border-radius: 10rpx;

      .text-box {
        width: 100%;

        .title {
          font-family: Alibaba PuHuiTi;
          font-weight: bold;
          font-size: 44rpx;
          color: #ff6205;
          line-height: 1;
        }

        .desc {
          font-family: Alibaba PuHuiTi;
          font-weight: 400;
          font-size: 30rpx;
          color: #363635;
          line-height: 42rpx;
          margin-top: 25rpx;

          .p {
            margin-top: 20rpx;
          }
        }

        .textDes {
          width: 100%;
          line-height: 40upx;
        }
      }
    }
  }

  .butBox {
    height: 130rpx;
    width: 100%;
    padding-top: 20rpx;
    background-color: transparent;

    .submitbut {
      width: 640rpx;
      height: 78rpx;
      text-align: center;
      line-height: 78rpx;
      background: linear-gradient(90deg, #ff9000, #ff5000);
      box-shadow: 0rpx 4rpx 2rpx 0rpx #ff6c00;
      border-radius: 39rpx;
      border: 3rpx solid #ffeac3;
      font-family: Source Han Sans CN;
      font-weight: 400;
      font-size: 28rpx;
      color: #ffffff;
      text-shadow: 0rpx 4rpx 4rpx rgba(244, 182, 58, 0.75);
    }
  }

  .informationShow-box {
    .flex-items {
      input {
        padding-left: 16upx;
      }
    }

    .phoneStyle {
      input {
        background: #eeeeee;
        color: #999999;
      }
    }

    .informationShow-centent {
      width: 520upx;
      height: 550upx;

      .recruitName {
        border: 2upx solid #dddddd;
        width: 300upx;
        height: 48upx;
      }

      .recruitIphone {
        border: 2upx solid #dddddd;
        width: 300upx;
        height: 48upx;
      }

      .massageDes-but {
        position: absolute;
        bottom: 0;
      }

      .exitBut {
        border: 1upx solid #e5e5e5;
        width: 260upx;
        height: 90upx;
        text-align: center;
        line-height: 90upx;
      }

      .submitbut {
        background: linear-gradient(90deg, #ff9000, #ff5000);
        width: 260upx;
        height: 90upx;
        text-align: center;
        line-height: 90upx;
        color: #fff;
      }
    }
  }
}

::v-deep .uni-nav-bar-text {
  font-family: Source Han Sans CN VF;
  font-weight: 500;
  font-size: 38rpx;
  color: #fff;
}

::v-deep .uni-navbar {
  transition: background-color .5s linear;
}
</style>
